<!--
 * @Author: 噜噜雯雯 2199987619@qq.com
 * @Date: 2025-06-10 14:37:36
 * @LastEditors: 噜噜雯雯 2199987619@qq.com
 * @LastEditTime: 2025-09-26 09:26:20
 * @FilePath: \linePatrol\vue-element-plus-admin\src\views\linePatrol\LssuePlan\components\facTaskList.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<script setup lang="tsx">
import { ContentWrap } from '@/components/ContentWrap'
import { useI18n } from '@/hooks/web/useI18n'
import { Table } from '@/components/Table'
import { useTable } from '@/hooks/web/useTable'
import { unref, reactive, watch, computed } from 'vue'
import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
import { usePatrolGroupStore } from '@/store/modules/PlanGroupStore'
import PlanGroupApi from '@/api/linePatrol/PlanGroupApi'
import { useRoute, useRouter } from 'vue-router'
import { StateInfoList } from '@/api/linePatrol/type'
import SetSecurCheckApi from '@/api/securcheck/SetSecurCheck'
const GroupStore = usePatrolGroupStore()
const route = useRoute()
const planType = route.meta.customParams as any
const apiStrategies = {
  LssuePlan: {
    detail: PlanGroupApi.GetStateInfoList
  },
  IssueUser: {
    detail: SetSecurCheckApi.GetStateInfoList
  },
  IssueCustomerUnit: {
    detail: SetSecurCheckApi.GetStateInfoList
  }
}

const recorders = computed(() => {
  if (planType.planType == 'LssuePlan') {
    return GroupStore.LssuePlanID
  } else if (planType.planType == 'IssueUser') {
    return GroupStore.IssueUserID
  } else {
    return GroupStore.IssueCustomerUnitID
  }
})
const currentStrategy = apiStrategies[planType.planType]
const { tableRegister, tableState, tableMethods } = useTable({
  fetchDataApi: async () => {
    const { currentPage, pageSize } = tableState
    const res = await currentStrategy.detail({
      pageNum: unref(currentPage),
      pageSize: unref(pageSize),
      uuid: recorders.value?.uuid
    })
    return {
      list: res.rows,
      total: res.total
    }
  }
})
const { loading, dataList, total, currentPage, pageSize } = tableState
const { getList } = tableMethods

watch(recorders, () => {
  getList()
})
const { push } = useRouter()
const { t } = useI18n()

const crudSchemas = reactive<CrudSchema[]>([
  {
    field: 'index',
    label: t('tableDemo.index'),
    type: 'index'
  },
  {
    field: 'taskName',
    label: t('任务名称'),
    width: 150,
    search: {
      hidden: true
    }
  },
  {
    field: 'stateToDo',
    label: t('待办状态计数'),
    search: {
      hidden: true
    }
  },
  {
    field: 'stateSuc',
    label: t('按时完成计划数'),
    search: {
      hidden: true
    }
  },
  {
    field: 'stateOutSuc',
    label: t('超期完成计数'),
    search: {
      hidden: true
    }
  },
  {
    field: 'stateOutNo',
    label: t('超期未完成计数'), //暂无
    search: {
      hidden: true
    }
  }
])
//高亮选中
const handleCurrentChange = async (currentRow: StateInfoList) => {
  push(
    `/linePatrol/PatrolScheme/ShowPlanList?taskName=${currentRow.taskName}&groupUserCom=${planType.groupUserCom}`
  )
}
// @ts-ignore
const { allSchemas } = useCrudSchemas(crudSchemas)
</script>

<template>
  <ContentWrap
    :title="t(`计划周期列表--${recorders?.planName == undefined ? '' : recorders?.planName}`)"
  >
    <Table
      v-model:pageSize="pageSize"
      v-model:currentPage="currentPage"
      :highlight-current-row="true"
      :columns="allSchemas.tableColumns"
      :data="dataList"
      :loading="loading"
      :pagination="{
        total: total,
        pageSize: pageSize
      }"
      @current-change="handleCurrentChange"
      @register="tableRegister"
    />
  </ContentWrap>
</template>
@/store/modules/PlanGroupApi@/api/linePatrol/PlanGroupApi
